SET(ODBC_BINARY_DIR ${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE})
SET(ODBC_SOURCE_WIX_DIR ${CMAKE_SOURCE_DIR}/wininstall)
MESSAGE(STATUS "BINARY_DIR ${ODBC_BINARY_DIR}")



# Get revision number
IF(WITH_REVNO)
  EXECUTE_PROCESS(COMMAND bzr log -l1
                  COMMAND FINDSTR revno
  OUTPUT_VARIABLE revno)
  STRING(REPLACE "revno: " "" revno ${revno})
  STRING(REPLACE "\n" "" revno ${revno})
ENDIF()
IF(NOT WIX_DIR)
  SET(WIX_DIR "$ENV{WIX}/bin/")
ENDIF()
SET(PRODUCT_NAME "MariaDB ODBC Driver")
SET(PRODUCT_MANUFACTURER "MariaDB")
SET(PRODUCT_VERSION "${MARIADB_ODBC_VERSION_MAJOR}.${MARIADB_ODBC_VERSION_MINOR}.${MARIADB_ODBC_VERSION_PATCH}")

IF(WITH_SIGNCODE)
ENDIF()

IF(CMAKE_SIZEOF_VOID_P EQUAL 8)
  SET(PRODUCT_NAME "${PRODUCT_NAME} 64-bit")
  SET(PLATFORM "win64")
  SET(IS_WIN64 "yes")
  SET(WIXPLATFORM "x64")
  SET(FOLDER "ProgramFiles64Folder")
  SET(GUID_REGISTRY "E35BF41F-89A1-4691-8F62-09922C04C13B")
  SET(GUID_SETUP "BF255F46-18CA-4244-9A17-6B33BDAAFBF4")
  SET(GUID_DRIVER "3535FD95-1F44-454E-A6E4-81F865E8C57F")
  SET(GUID_DEBUG "4FA6E79A-4630-4CB8-A4E1-00A4740E9280")
ELSE()
  SET(PLATFORM "win32")
  SET(IS_WIN64 "no")
  SET(WIXPLATFORM "x86")
  SET(FOLDER "ProgramFilesFolder")
  SET(GUID_REGISTRY "ACFC9B33-5D1F-4EA2-A4DB-1E37A2BAF86B")
  SET(GUID_SETUP "16E13D0B-7BFE-4BC4-A524-940716EE749F")
  SET(GUID_DRIVER "8BD16D93-30E0-4DF0-8B40-9A5A3D967DD6")
  SET(GUID_DEBUG "2EA8B4DD-F470-4362-8D87-59090D255981")
ENDIF()

CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/wininstall/mariadb_odbc.xml.in
               ${CMAKE_BINARY_DIR}/wininstall/mariadb_odbc.xml)
IF(${revno})
  SET(MSI_PACKAGE "mariadb-connector-odbc-${PRODUCT_VERSION}-r${revno}-${PLATFORM}.msi")
ELSE()
  SET(MSI_PACKAGE "mariadb-connector-odbc-${PRODUCT_VERSION}-${PLATFORM}.msi")
ENDIF()

ADD_CUSTOM_TARGET(
        ${MSI_PACKAGE}
        COMMAND ${WIX_DIR}light.exe -ext WixUIExtension mariadb_odbc.wixobj -o ${MSI_PACKAGE})

SET_TARGET_PROPERTIES(${MSI_PACKAGE} PROPERTIES EXCLUDE_FROM_ALL OFF)

ADD_CUSTOM_TARGET(
        ODBC_WIX
        DEPENDS mariadb_odbc.xml
        COMMAND ${WIX_DIR}candle.exe mariadb_odbc.xml -o mariadb_odbc.wixobj)

ADD_DEPENDENCIES(${MSI_PACKAGE} ODBC_WIX)
ADD_DEPENDENCIES(ODBC_WIX maodbc maodbcs)

